package com.example.goods_service.dao;


import com.example.goods_service.vo.*;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestParam;

import javax.websocket.server.ServerEndpoint;
import java.util.List;

@Repository
@Mapper
public interface GoodsDao_liuyubin {
    //全部评论单
    @Select("select count(id) from t_user_content where commodity_id=${id}")
    int gradedan(int id);
    //全部评论
    @Select("SELECT count(id) as id FROM t_user_content where commodity_id=${id}\n" +
            "UNION all\n" +
            "select count(id) fROM t_user_content where comment_grade=1 and commodity_id=${id}\n"+
            "UNION all\n"+
            "select count(id) FROM t_user_content where comment_grade=2 and commodity_id=${id}\n" +
            "UNION all\n" +
            "select count(id) FROM t_user_content where comment_grade=3 and commodity_id=${id}")
    List<T_user_content_quantity> grade(int id);
    //查询全部评价
    @Select("SELECT a.id,b.user_id ,b.user_img,b.user_name, a.commodity_id ,a.comment_content ,a.message_status,a.comment_grade,a.comment_time   FROM t_user_content a,user_data b where commodity_id=${id} and a.User_id=b.user_id")
    List<T_user_content> gradehzh(int id);
    @Select("SELECT a.id,b.user_id ,b.user_img,b.user_name, a.commodity_id ,a.comment_content ,a.message_status,a.comment_grade,a.comment_time   FROM t_user_content a,user_data b where  a.User_id=b.user_id")
    List<T_user_content> selectqbpl();
    @Select("SELECT b.user_id,b.user_img,b.user_name,a.id,a.commodity_id,a.comment_content,a.message_status,a.comment_grade,a.comment_time FROM t_user_content a,user_data b where commodity_id=${id} and comment_grade=${grade} and a.User_id=b.user_id")
    List<T_user_content> gradehzh2(int id,int grade);
    //查询商家评价
    @Select("select id,commodity_id,shop_id,User_id,reply_content,comment_time,comment_id from t_shop_reply")
    List<T_shop_reply>selectshoppj();
    //查询商家评价浏览
    @Select("select id,b.user_name,commodity_id,comment_content,message_status,comment_grade,comment_time from t_user_content a,user_data b where message_status=${id} and a.User_id=b.user_id; ")
    List<T_user_content>selectshopliul(int id);

    //查询用户子评论
    @Select("SELECT a.id,a.commodity_id,a.comment_time,a.comment_id,a.reply_content,b.user_img,b.user_name  FROM t_user_reply a,user_data b where a.User_id=b.user_id")
    List<T_user_reply>zpl();
    //查询用户
    @Select("select * from user_data")
    List<T_user>user();
    //添加子评论
    @Insert("insert into t_user_reply(commodity_id,User_id,comment_id,reply_content,comment_time)value(${commodity_id},${user_id},${comment_id},'${replu_content}',now())")
    boolean insertreply(int commodity_id,int user_id,int comment_id,String replu_content);

    @Select("select * from t_shop_reply where User_id=${id}")
    List<T_shop_reply>selectshopreply(int id);
    //查询全部好评
    @Select("select count(id) from t_user_content where commodity_id=${id} and comment_grade=1;")
    int selectqbhp(int id);
    //修改浏览状态
    @Update("update t_user_content set message_status=${status} where id=${id}")
    boolean update(int id,int status);
   //根据id查评论
    @Select("select id,b.user_name,commodity_id,comment_content,message_status,comment_grade,comment_time from t_user_content a,user_data b where id=${id} and a.User_id=b.user_id;")
    List<T_user_content>huifsel(int id);
    //添加商家回复
    @Insert("insert into t_shop_reply(commodity_id,shop_id,User_id,reply_content,comment_time,comment_id)values(${sp},${shop},${user},'${reply}',now(),${commentid})")
    boolean insert(int sp,int shop,int user,String reply,int commentid);
    //模糊查询
    @Select("select id,b.user_name,commodity_id,comment_content,message_status,comment_grade,comment_time from t_user_content a,user_data b where  a.User_id=b.user_id\n" +
            "and comment_content like '%${value}%'")
    List<T_user_content>mhcx(String value);
}
